<test>
    <settings>
        <max_insert_threads>8</max_insert_threads>
        <optimize_use_projections>0</optimize_use_projections>
    </settings>

    <substitutions>
        <substitution>
            <name>key_type</name>
            <values>
                <value>key_string</value>
                <value>key_string_two_level</value>
                <value>key_fixed_string</value>
                <value>key_int64</value>
                <value>key_int64_two_level</value>
                <value>key_int32</value>
                <value>key_int32_two_level</value>
                <value>Key_int16</value>
                <value>key_int8</value>
            </values>
        </substitution>
    </substitutions>
    <create_query>
        CREATE TABLE t_nullable
        (
        key_string Nullable(String),
        key_string_two_level Nullable(String),
        key_fixed_string Nullable(FixedString(3)),
        key_int64 Nullable(Int64),
        key_int64_two_level Nullable(Int64),
        key_int32 Nullable(Int32),
        key_int32_two_level Nullable(Int32),
        Key_int16 Nullable(Int16),
        key_int8 Nullable(Int8),
        i1 Nullable(Int64),
        i2 Nullable(Int64),
        )
        ENGINE = MergeTree
        ORDER BY tuple()
    </create_query>
    <fill_query>insert into t_nullable select ['aa','bb','cc','dd'][number % 10000 + 1], ['aa','bb','cc','dd'][number % 200000 + 1], ['aa','bb','cc','dd'][number % 4 + 1], toInt64(number%10000), toInt64(number%200000), toInt32(number%10000), toInt32(number%200000), toInt16(number%10000), toInt8(number%100), number%6000+1, number%5000+2 from numbers_mt(20000000)</fill_query>
    <fill_query>insert into t_nullable select ['aa','bb','cc','dd'][number % 10000 + 1], ['aa','bb','cc','dd'][number % 200000 + 1], ['aa','bb','cc','dd'][number % 4 + 1], toInt64(number%10000), toInt64(number%200000), toInt32(number%10000), toInt32(number%200000), toInt16(number%10000), toInt8(number%100), number%6000+1, number%5000+2 from numbers_mt(20000000)</fill_query>
    <fill_query>insert into t_nullable select ['aa','bb','cc','dd'][number % 10000 + 1], ['aa','bb','cc','dd'][number % 200000 + 1], ['aa','bb','cc','dd'][number % 4 + 1], toInt64(number%10000), toInt64(number%200000), toInt32(number%10000), toInt32(number%200000), toInt16(number%10000), toInt8(number%100), number%6000+1, number%5000+2 from numbers_mt(20000000)</fill_query>
    <fill_query>insert into t_nullable select ['aa','bb','cc','dd'][number % 10000 + 1], ['aa','bb','cc','dd'][number % 200000 + 1], ['aa','bb','cc','dd'][number % 4 + 1], toInt64(number%10000), toInt64(number%200000), toInt32(number%10000), toInt32(number%200000), toInt16(number%10000), toInt8(number%100), number%6000+1, number%5000+2 from numbers_mt(20000000)</fill_query>
    <fill_query>OPTIMIZE TABLE t_nullable FINAL</fill_query>
    <query>select min(i1), min(i2) from t_nullable group by {key_type} format Null</query>

    <drop_query>drop table if exists t_nullable</drop_query>
</test>
